<!DOCTYPE html>
<html lang=en>

<head>
  <meta charset=UTF-8>
  <meta name=viewport content="width=device-width,initial-scale=1">
  <meta http-equiv=X-UA-Compatible content="ie=edge">
  <title>Document</title>
  <link rel=stylesheet href=../tools/bootstrap-3.3.7-dist/css/bootstrap.min.css>
  <link rel=stylesheet href=../css/base.css>
  <link rel=stylesheet href=../css/login.css>
  <style>
    body {
      background-image: url(../message/背景图.png)
    }

    .jumbotron {
      width: 800px;
      margin: 50px auto;
      background: rgba(0, 0, 0, 0)
    }

    .jumbotron>h1 {
      width: 600px;
      margin: 50px auto;
      color: azure
    }

    .login {
      margin: 0 auto;
      font-size: 16px;
      color: azure
    }

    .form-control {
      width: 300px
    }
  </style>
</head>

<body>
  <div class=jumbotron>
    <h1>欢迎光临SHOP</h1>
    <div class=login>
      <form class=form-horizontal>
        <div class=form-group><label for=username class="col-sm-2 control-label">用户名</label>
          <div class=col-sm-10><input type=text class=form-control id=username placeholder=用户名></div>
        </div>
        <div class=form-group><label for=password class="col-sm-2 control-label">密码</label>
          <div class=col-sm-10><input type=password class=form-control id=password placeholder=密码></div>
        </div>
        <div class=form-group>
          <div class="col-sm-offset-2 col-sm-10"><button type=submit class="btn btn-default">登录</button></div>
        </div>
      </form>
    </div>
  </div>
  <script src=../js/jquery.min.js></script>
  <script src=../js/cookie.js></script>
  <script>// 应该写在数据库中
    let time = 5;
    $('form').submit(function () {
      let name = $('[type="text"]').val();
      let pwd = $('[type="password"]').val();

      const p = new Promise(function (f, r) {
        $.ajax({
          url: '../server/goods_login.php',
          type: 'post',
          data: { userName: name, userPwd: pwd },
          dataType: 'json',
          success: f,
          error: r,
        })
      })
      p.then(function (res) {
        //  console.log(res);
        if (res.result === 1) {
          window.alert('恭喜您登录成功');
          // window.history.back();
          if (window.location.search === '') {
            window.location.href = './index.html'
          } else {
            let url = window.location.search.substr(5);
            window.location.href = url;
          }
          mySetCookie('login', 1, 7 * 24 * 60 * 60, '/');
        } else if (res.result === 0) {
          time--;
          if (time === 0) {
            window.alert('账号冻结');
            $('[type="text"]').prop('disabled', true);
            $('[type="password"]').prop('disabled', true);
            $('button').prop('disabled', true);
            return;
          }
          window.alert(`您今天还可以错${time}次`);
        }
      })


      return false;
    })</script>
  <script></script>
</body>

</html>